#include <cstdio>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

#define MAXN 1000000
#define _cp(a,b) ((a)<=(b))
typedef double elem_t;
elem_t _tmp[MAXN];

int inv(int n,elem_t* a){
    int l=n>>1,r=n-l,i,j;
    int ret=(r>1?(inv(l,a)+inv(r,a+l)):0);
    for (i=j=0;i<=l;_tmp[i+j]=a[i],i++)
        for (ret+=j;j<r&&(i==l||!_cp(a[i],a[l+j]));_tmp[i+j]=a[l+j],j++);
    memcpy(a,_tmp,sizeof(elem_t)*n);
    return ret;
}


struct point{double x,y;point(){};point(double _x, double _y):x(_x),y(_y){}};
struct Node{double x,y;Node(){};Node(double _x, double _y):x(_x),y(_y){}};
bool operator < ( const Node &a, const Node &b )
{
    if ( fabs( a.x - b.x ) > eps )
        return a.x < b.x;
    return a.y < b.y;
}

int parallel(point u1,point u2,point v1,point v2){
    return zero((u1.x-u2.x)*(v1.y-v2.y)-(v1.x-v2.x)*(u1.y-u2.y));
}

point intersection(point u1,point u2,point v1,point v2){
    point ret=u1;
    double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))
            /((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));
    ret.x+=(u2.x-u1.x)*t;
    ret.y+=(u2.y-u1.y)*t;
    return ret;
}

double l, r;
int n, ne;
__int64 pr, gd;
Node a[ MAXN ];
double b[ MAXN ];

void init( )
{
    int i;
    point p1, p2;
    double v1, v2, t;
    gd = pr = ne = 0;
    scanf("%lf%lf", &l, &r);
    for ( i = 0; i < n; i++ )
    {
        scanf("%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y);
        if ( fabs( p1.x - p2.x ) <= eps )
        {
            if ( p1.x > l + eps && p2.x < r - eps ) pr++;
            else gd++;
            continue;
        }
        v1 = p1.y + ( p2.y - p1.y ) / ( p2.x - p1.x ) * ( l - p1.x );
        v2 = p1.y + ( p2.y - p1.y ) / ( p2.x - p1.x ) * ( r - p1.x );
        a[ ne++ ] = Node( v1, v2 );
    }
    sort( a, a + ne );
    for ( i = 0; i < ne; i++ )
    {
        b[ i ] = a[ i ].y;
    //    printf("%lf ", b[ i ]);
    }
}

int main( )
{
    while ( scanf("%d", &n) != EOF )
    {
        init( );
        printf("%d\n", inv( ne, b ) + pr * ( n - pr - gd ));
    }
    return 0;
}
